package com.baozhun.mall.common.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import android.widget.ImageView

class RadiusImageView(var1: Context?, var2: AttributeSet?) : ImageView(var1, var2) {
    private var width = 0f
    private var height = 0f
    private var defaultRadius = 15
    private var leftTopRadius = 0
    private var rightTopRadius = 0
    private var rightBottomRadius = 0
    private var leftBottomRadius = 0

    init {
        init()
    }

    private fun init() {
        leftTopRadius = defaultRadius
        rightTopRadius = defaultRadius
        rightBottomRadius = defaultRadius
        leftBottomRadius = defaultRadius
    }

    fun setRadius(var1: Int, var2: Int, var3: Int, var4: Int) {
        leftTopRadius = var1
        rightTopRadius = var2
        rightBottomRadius = var3
        leftBottomRadius = var4
        this.invalidate()
    }

    override fun onLayout(var1: Boolean, var2: Int, var3: Int, var4: Int, var5: Int) {
        super.onLayout(var1, var2, var3, var4, var5)
        width = getWidth().toFloat()
        height = getHeight().toFloat()
    }

    override fun onDraw(var1: Canvas) {
        val var2 = Math.max(leftTopRadius, leftBottomRadius)
        val var3 = Math.max(rightTopRadius, rightBottomRadius)
        val var4 = var2 + var3
        val var5 = Math.max(leftTopRadius, rightTopRadius)
        val var6 = Math.max(leftBottomRadius, rightBottomRadius)
        val var7 = var5 + var6
        if (width >= var4.toFloat() && height > var7.toFloat()) {
            val var8 = Path()
            var8.moveTo(leftTopRadius.toFloat(), 0.0f)
            var8.lineTo(width - rightTopRadius.toFloat(), 0.0f)
            var8.quadTo(width, 0.0f, width, rightTopRadius.toFloat())
            var8.lineTo(width, height - rightBottomRadius.toFloat())
            var8.quadTo(width, height, width - rightBottomRadius.toFloat(), height)
            var8.lineTo(leftBottomRadius.toFloat(), height)
            var8.quadTo(0.0f, height, 0.0f, height - leftBottomRadius.toFloat())
            var8.lineTo(0.0f, leftTopRadius.toFloat())
            var8.quadTo(0.0f, 0.0f, leftTopRadius.toFloat(), 0.0f)
            var1.clipPath(var8)
        }
        super.onDraw(var1)
    }
}